package com.ymatou.app.api.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.api.parameter.EditAddressBean;
import com.ymatou.app.api.service.EditAddressCall;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.business.service.YmtCallService;
import com.ymttest.utils.constant.ECode;

/**
 * 编辑收货地址 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_EditAddress {
	private static EditAddressBean editaddressbean;
	private static EditAddressCall editaddresscall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("编辑收货地址");
	}

	@Before
	public void caseUp() {
		editaddressbean = new EditAddressBean();
		editaddresscall = new EditAddressCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(editaddresscall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_EditAddress_001() {
		Logger.start(true,"编辑收货地址成功");
		try {
			// 注册获取token和userid
			
			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			// Logger.debug(UserId+";"+AccessToken);
			// 添加一条数据
			YmtCallService ymt = new YmtCallService();
			ymt.addAddress(AccessToken, UserId);
			List AddressIdList = ymt.getAddressId(AccessToken, UserId);
			// 设置数据
			editaddressbean.setAccessToken(AccessToken);
			Logger.comment("AccessToken:" + AccessToken);
			editaddressbean.setUserId(UserId);
			Logger.comment("UserId:" + UserId);
			editaddressbean.setAddressId((Integer) AddressIdList.get(0));
			Logger.comment("AddressId:" + AddressIdList.get(0));
			String Address1 = "北京市,北京市,朝阳区";
			Logger.comment("Address1:" + Address1);
			editaddressbean.setAddress1(Address1);
			String ProvinceName = "北京市";
			Logger.comment("ProvinceName:" + ProvinceName);
			editaddressbean.setProvinceName(ProvinceName);
			String CityName = "北京市";
			Logger.comment("CityName:" + CityName);
			editaddressbean.setCityName(CityName);
			String DistrictName = "朝阳区";
			Logger.comment("DistrictName:" + DistrictName);
			editaddressbean.setDistrictName(DistrictName);
			String Details = "人民广场47号504";
			Logger.comment("Details:" + Details);
			editaddressbean.setDetails(Details);
			String PostCode = "300001";
			Logger.comment("PostCode:" + PostCode);
			editaddressbean.setPostCode(PostCode);
			String Mobile = "110";
			Logger.comment("Mobile:" + Mobile);
			editaddressbean.setMobile(Mobile);
			String Email = "qq@qq.com";
			Logger.comment("Email:" + Email);
			editaddressbean.setEmail(Email);
			String Recipient = "田喜龙";
			Logger.comment("Recipient:" + Recipient);
			editaddressbean.setRecipient(Recipient);
			boolean IsDefault = true;
			Logger.comment("IsDefault:" + IsDefault);
			editaddressbean.setIsDefault(IsDefault);
			// 发送数据
			editaddresscall.setData(editaddressbean);
			editaddresscall.callService();
			/*
			 * Logger.debug(editaddresscall.getEntityString());
			 * Logger.debug(editaddresscall.getReturnData());
			 */
			Logger.comment("editaddresscall send:" + editaddresscall.getEntityString());
			Logger.comment("editaddresscall response:" + editaddresscall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, editaddresscall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.APP_MSG1, editaddresscall.getMsg(), "验证Msg消息");
			Logger.verifyEquals(ECode.BCODE0, editaddresscall.getBCode(), "验证BCode");
			Logger.verifyEquals("true", editaddresscall.getResult(), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}